package com.yonyou.brigade.third_parties.fanscar.util;

import com.xiaoleilu.hutool.util.IdcardUtil;
import com.yonyou.brigade.third_parties.fanscar.model.FanscarUser;
import com.yonyou.ybzboot.uc.dto.UcUserDto;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  单点转换工具类
 * </p>
 *
 * @author kangfw5
 * @since : 2019-03-07
 */
public class UserConvertUtil {

    public static FanscarUser convertToFanscarUser(UcUserDto ucUserDto) {
        FanscarUser fanscarUser = new FanscarUser();
        fanscarUser.setEmployeeId(ucUserDto.getPersonCode());
        fanscarUser.setEmployeeName(ucUserDto.getUserName());
        fanscarUser.setEmployeeNumber(ucUserDto.getPersonCode());
        fanscarUser.setDepartmentCode(ucUserDto.getOrgPk());
        fanscarUser.setJobGradeCode(ucUserDto.getPostPk());
        fanscarUser.setMobile(ucUserDto.getPhone());
        String passengerId = ucUserDto.getPassengerId();
        // 验证身份证有效性病设置性别 0：女 1：男 3：未知
        try{
            if (StringUtils.isNotEmpty(passengerId) && IdcardUtil.isValidCard(passengerId)) {
                fanscarUser.setGender(IdcardUtil.getGenderByIdCard(passengerId));
            } else {
                fanscarUser.setGender(3);
            }
        } catch (Exception e) {
            fanscarUser.setGender(3);
        }
        fanscarUser.setStatus(ucUserDto.getValid());
        return fanscarUser;
    }

    public static List<FanscarUser> convertToFanscarUserList(List<UcUserDto> ucUserDtoList) {
        List<FanscarUser> fanscarUserList = new ArrayList<>();
        for (UcUserDto ucUserDto : ucUserDtoList) {
            FanscarUser fanscarUser = convertToFanscarUser(ucUserDto);
            fanscarUserList.add(fanscarUser);
        }
        return fanscarUserList;
    }
}
